import pyaudio
import sys, string

chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 22050
RECORD_SECONDS =5

p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
                channels = CHANNELS, 
                rate = RATE, 
                input = True,
                output = True)

FILE = open("log.txt", "w")

print "* recording"
for i in range(0, RATE / chunk * RECORD_SECONDS):
    data = stream.read(chunk)
    ii = False
    gg = 0
    for d in data:
        # neglect low
        if ii is True:
            ii = False
            gg = ord(d) + gg
           
           
        else:
            ii = True
    FILE.write(str(gg)+"\n")
    
      
print "* done"
FILE.close();
stream.stop_stream()
stream.close()
p.terminate()
